from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask import render_template, redirect

import os


app = Flask(__name__, static_url_path='')
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:root@localhost:3306/suda_course'
app.secret_key = os.urandom(24)

db = SQLAlchemy(app)

from app.api import api_blueprint
from app.admin import admin_blueprint
from app.model.user import User
from app.api import login
from app.auth.session_check import SessionCheck

app.register_blueprint(api_blueprint, url_prefix='/api')
app.register_blueprint(admin_blueprint, url_prefix='/admin')


@app.route('/')
def index():
    return redirect('index.html')
    # if SessionCheck.check_login():
    #     site = {
    #         'is_logged' : True,
    #         'title' : '课程管理系统',
    #         'current_page' : 'home',
    #     }
    #     return render_template("index.html", site = site)
    # if SessionCheck.get_identity() == 0:
    #     return redirect('/admin/index')
    # elif SessionCheck.get_identity() == 1:
    #     return redirect('teacher/index')
    # return redirect('/login')

@app.route('/login')
def login():
    if SessionCheck.check_login():
        return redirect('/')
    site = {
        'is_logged': False,
        'title': '课程管理系统',
        'current_page': 'login',
    }
    return render_template("login.html", site=site)

